﻿///////////////////////////////////////////////////////////////////////////////
//
// This file is part of the BassDrop project
//   https://code.google.com/p/bass-drop/
//
//
// Creator:	Gergely Krajcsovszki (krajcsovszkig@hotmail.com)
// Date:	2013-12-23 19:30
//
//
// Copyright © 2013-2014. Gergely Krajcsovszki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
///////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using BassDrop.Core.Common.Localization;
using BassDrop.Core.Common.Options;
using BassDrop.Core.Common.Options.Items;
using BassDrop.Core.Common.Plugins;
using BassDrop.DesktopClient.UI.Controls.OptionItems;

namespace BassDrop.DesktopClient.UI.Views
{
	/// <summary>
	/// View / page for showing the list of OptionsItems for something
	/// </summary>
	public partial class CustomOptionsView : ContentViewBase
	{
		/// <summary>
		/// Do not use
		/// </summary>
		private CustomOptionsView()
		{
			InitializeComponent();
		}

		/// <summary>
		/// Creates a new options view for the passed list of options
		/// </summary>
		/// <param name="options"></param>
		public CustomOptionsView( OptionsSetBase options )
			: this()
		{
			if ( options == null )
			{
				var label = new Label();
				label.SetBinding( Label.ContentProperty, new Binding()
					{
						Path = new PropertyPath( "(0)", typeof( Strings ).GetProperty( "LabelCustomOptionsViewNoItems" ) ),
						FallbackValue = "##No options are available for this item"
					} );
				label.Style = FindResource( "StyleGeneralHeadingControl" ) as Style;
				StackPanelContent.Children.Add( label );
			}
			else
			{
				foreach ( var item in options.Options )
				{
					StackPanelContent.Children.Add( CreateLayout( item ) );
				}
			}
		}

		/// <summary>
		/// Creates an appropriate UI control for the passed options item and returns it
		/// </summary>
		/// <param name="item"></param>
		/// <returns></returns>
		private UIElement CreateLayout( OptionsItemBase item )
		{
			if ( item is ActionOptionsItem )
			{
				return new ActionOptionsItemUI( (ActionOptionsItem) item );
			}
			else if ( item is BooleanPropertyOptionsItem )
			{
				return new BooleanPropertyOptionsItemUI( (BooleanPropertyOptionsItem) item );
			}
			else if ( item is EnumPropertyOptionsItem )
			{
				return new EnumPropertyOptionsItemUI( (EnumPropertyOptionsItem) item );
			}
			else if ( item is GroupOptionsItem )
			{
				// TODO: többi fajta option
			}
			else if ( item is NumericPropertyOptionsItem )
			{

			}
			else if ( item is StringPropertyOptionsItem )
			{

			}
			else if ( item is TabbedOptionsItem )
			{

			}
			else if ( item is TextOptionsItem )
			{
				return new TextOptionsItemUI( (TextOptionsItem) item );
			}

			throw new InvalidOperationException( Strings.ExceptionMissingGuiForOptionsItem );
		}
	}
}
